import { priority } from "utils/constants/definetypes";

 

export default 
{
    war:{
        attack(roomF:string,roomTarget:string,team4:ITeamConfig={
            type:"Team4",
            creep:[
                [
                    {
                        Role:"idaBlue",
                        
                        body:[[RANGED_ATTACK,4], [HEAL,1],[MOVE,5]]

                    },
                    2
                ],
                [
                    {
                        Role:"idaHeal",
                        
                        body:[[RANGED_ATTACK,1],  [HEAL,4],[MOVE,5]]
                    },
                    2
                ],
            ]
        },count=1,benchRooms=[])
        {
            /*
            war.attack("E44S47","E41S44",{
            type:"Team4",
            creep:[
                [
                    {
                        Role:"idaBlue",
                        
                        body:[[RANGED_ATTACK,10], [HEAL,15],[MOVE,25]]

                    },
                    2
                ],
                [
                    {
                        Role:"idaHeal",
                        
                        body:[[RANGED_ATTACK,10],  [HEAL,15],[MOVE,25]]
                    },
                    2
                ],
            ]
        },1,['E41S46','E39S45','E38S42'])
            */
            // war.attack("E53S44","E56S41")
            // 需要配置 team,required,设置 team required
            // 同时还有creep的body需求配置。然后进行team绑定时，自动添加到team成员里
            // 战争任务创建
           /*
            const wteam ={
                type:"Team4",
                creep:[
                    [
                        {
                            Role:"idaBlue",
                            boost:3,
                            body:[[RANGED_ATTACK,12],[TOUGH,12],[RANGED_ATTACK,12],[HEAL,4],[MOVE,10]]

                        },
                        2
                    ],
                    [
                        {
                            Role:"idaHeal",
                            boost:3,
                            body:[[RANGED_ATTACK,4],[TOUGH,12], [HEAL,24],[MOVE,10]]
                        },
                        2
                    ],
                ]
            }
           */

            const plan:IWarPlan={
                creep:[],
                team:[[team4,count]]
            }
            return this.attackByPlan(roomF,roomTarget,plan,benchRooms)
        },
        attackByPlan(roomF:string,roomTarget:string,plan:IWarPlan,benchRooms=[])
        {
            
            /* const plan2:IWarPlan=
            {
                creep:[[{Role:"idaRed",body:[[ATTACK,2], [HEAL,1],[MOVE,3]]},2]],
                team:[ ]
            }
             */
            // 进攻指定房间
            // 发起战争任务
            const wartask:ITeamTaskData<"defend">  ={
                type: "defend",
                room: roomTarget,
                arg: {
                    benchRooms:benchRooms,
                    enemy: [],
                    structures: [],
                },
                creeps: [],
                teams: {} as any,
                creepRequired: plan.creep,
                required: plan.team,
                cost: 0
            }
            const teamTask:ITaskDeclare["team"]=
            {
                id:`${roomTarget}_war`,
                priority: priority.A,
                ttl: -1,
                type: "team",
                data: wartask,
                shard: 0,
                condition:{
                    type:"taskFlag",
                }
            }
            if(Game.rooms[roomF].addNewTask(teamTask))
            {
                if(!Game.flags[`${roomTarget}_war`])
                {
                    new RoomPosition(40,5,roomF).createFlag(`${roomTarget}_war`)
                }
                
                return `任务添加完成 ${JSON.stringify(teamTask)}`
            }
            return teamTask;
        }
    }
}